package com.zsummer.zero.design.create.singleton;

import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadDemo1 {

	public static void main(String[] args) throws Exception {
		ExecutorService executor = new ThreadPoolExecutor(100, 100, 0L, TimeUnit.MILLISECONDS,
				new LinkedBlockingQueue<Runnable>());
		long start = System.currentTimeMillis();
		ArrayList<Future<?>> futureList = new ArrayList<Future<?>>();
		for (int i = 0; i < 100; i++) {
			Future<?> future = executor.submit(new Runnable() {
				
				@Override
				public void run() {
					try {
						Teacher teacher = Teacher.getInstance();
						System.out.println(teacher);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
				}
			});
			futureList.add(future);
		}
		for (Future<?> future : futureList) {
			future.get();
		}
		long end = System.currentTimeMillis();
		long interTime = end -start;
		System.out.println("interTime: " + interTime);
		executor.shutdown();
	}
}
